﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.Odbc;
using System.Data.OleDb;

namespace WinCurrentPrice
{
    public partial class frmMain : Form
    {
        string strOdbcConn ;

        public frmMain()
        {
            InitializeComponent();

            strOdbcConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + GetStartUpPath ()+ ";Extended Properties=dBASE IV;";
        }

        private void btnSHGetPrice_Click(object sender, EventArgs e)
        {
            using (OleDbConnection odbcConn = new OleDbConnection(strOdbcConn))
            {
                odbcConn.Open();
                OleDbDataAdapter OdbcAda = new OleDbDataAdapter();
                OdbcAda.SelectCommand = new OleDbCommand();
                OdbcAda.SelectCommand.Connection = odbcConn;
                OdbcAda.SelectCommand.CommandType = CommandType.Text;
                OdbcAda.SelectCommand.CommandText = "select S1 as 代码, S2 as 名称, S8 as 最新价 from SHOW2003 where s1 in ('600571','600570')";

                DataSet ds = new DataSet();
                OdbcAda.Fill(ds);

                this.dataGridView1.DataSource = ds.Tables[0];
            }
        }

        private void btnGetSZPrice_Click(object sender, EventArgs e)
        {
            using (OleDbConnection odbcConn = new OleDbConnection(strOdbcConn))
            {
                odbcConn.Open();
                OleDbDataAdapter OdbcAda = new OleDbDataAdapter();
                OdbcAda.SelectCommand = new OleDbCommand();
                OdbcAda.SelectCommand.Connection = odbcConn;
                OdbcAda.SelectCommand.CommandType = CommandType.Text;
                OdbcAda.SelectCommand.CommandText = "select HQZQDM as 代码, HQZQJC as 名称, HQZJCJ as 最近成交价 from SJSHQ";

                DataSet ds = new DataSet();
                OdbcAda.Fill(ds);

                this.dataGridView2.DataSource = ds.Tables[0];
            }
        }

        private string GetStartUpPath()
        {
            string exepath = Application.ExecutablePath.ToLower().Replace("wincurrentprice.exe", string.Empty) + "Data\\";
            return exepath;
        }
    }
}
